/*************************************************************************
	> File Name: 004.HZOJ-48.完全背包_空间优化版.cpp
	> Author: Maureen 
	> Mail: Maureen@qq.com 
	> Created Time: 二  6/29 11:56:22 2021
 ************************************************************************/

#include <iostream>
using namespace std;

int n, V, v[10005], w[10005], ans[10005];

int main() {
    cin >> n >> V;
    for (int i = 1; i <= n; i++) {
        cin >> v[i] >> w[i];
    }
    for (int i = 1; i <= n; i++) {
        for (int j = v[i]; j <= V; j++) { //从前往后计算
            ans[j] = max(ans[j], ans[j - v[i]] + w[i]);
        }
    }
    cout << ans[V] << endl;

    return 0;
}
